<% /* $Id: submissions.jsp 99 2010-11-12 20:11:14Z altdotua@gmail.com $ */ %>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<%@ include file="header.jsp" %>

<%
	HashMap <String, Object> map = new HashMap<String, Object>();
	Map<String, String> params = Misc.remap(request);
	String value;
	
	if (null != (value = params.get("page")))
		map.put("page", Long.parseLong(value));
	else
		map.put("page", -1);
	if (null != (value = params.get("user_id")))
		map.put("userId", Long.parseLong(value));
	if (null != (value = params.get("judgement")))
		map.put("judgement", value);
	if (null != (value = params.get("problem_id")))
		map.put("contestProblemId", Long.parseLong(value));
	if (!contestUser.isJudge() && !contest.getShowFullSubmissions())
		map.put("userId", user.getId());
	
	if (!contestUser.isJudge())
	{
		map.put("visible", true);
	}
	
	map.put("contestId", contest.getId());
%>


<h2>Sent submissions</h2>

<table border="1" class="b1">
	<tr>
		<th class="b1">ID</th>
		<th class="b1">Time</th>
		<th class="b1">Size</th>
		<th class="b1">Problem</th>
		<th class="b1">Language</th>
		<th class="b1">User</th>
		<th class="b1">Result</th>
<%
	if (contest.getShowScore() || contestUser.isJudge())
	{
%>
		<th class="b1">Score</th>
<%
	}
%>
<%
	if (contest.getShowWrongTest() || contestUser.isJudge())
	{
%>
		<th class="b1">Failed test</th>
<%
	}
%>
<%
	if (contest.getShowMaxTime() || contestUser.isJudge())
	{
%>
		<th class="b1">MaxTime</th>
<%
	}
%>
<%
	if (contest.getShowMaxMemory() || contestUser.isJudge())
	{
%>
		<th class="b1">MaxMemory</th>
<%
	}
%>
			<th class="b1">State</th>
	</tr>
<%
	List<SubmissionEntry> entries = SubmissionsModel.getSubmissions(map);
	Map<Long, LanguageEntry> languages = LanguagesModel.getEntriesMap();
	Map<Long, ContestProblemEntry> problems = ContestProblemsModel.getEntriesMap();
	Map<Long, UserEntry> users = UsersModel.getEntriesMap();
	for (SubmissionEntry submission: entries)
	{
		String rowColor = "";
		String judgement = submission.getJudgement();
		if (submission.getDjudgeFlag() > 0)
		{
			if (judgement.equals("CE"))
			{	
				rowColor = "#cccccc";
			}
			else
			{
				if (submission.getFlagFirstTestOnly())
				{
					rowColor = "#cccccc";
				}
				else
				{
					if ("AC".equals(judgement))
						rowColor = "#aaffaa";
					else if ("WA".equals(judgement) || "TLE".equals(judgement) || "RE".equals(judgement))
						rowColor = "#ffaaaa";
					else
						rowColor = "#777777";
				}			
			}
		}
		else
		{
			rowColor = "#ffff00";
		}
		UserEntry userT = users.get(submission.getUserId());
		%>
		<tr bgcolor="<%= rowColor %>"  align="center">
			<td class="b1"><%= submission.getId() %></td>
			<td class="b1"><%= submission.getSubmissionTime() %></td>
			<td class="b1"><a href="<%= Linker.link("contests/source.jsp?contest_id=" + contest.getId() + "&submission_id=" + submission.getId()) %>"><%= (new PrintfFormat("%.1lf").sprintf(1.0 * submission.getSourceSize() / 1024)).replace(',', '.') %> КБ</a></td>
			<td class="b1"><a href="<%= Linker.link("problem.jsp?problem_id=" + submission.getContestProblemId()) %>"><%=problems.get(submission.getContestProblemId()) != null ? problems.get(submission.getContestProblemId()).getSid() : submission.getContestProblemId()%></a></td>
			<td class="b1"><%= languages.get(submission.getLanguageId()).getSid() %></td>
			<td class="b1"><%= userT == null ? submission.getUserId() : StringEscapeUtils.escapeHtml(userT.getUsername()) %></td>
			<td class="b1"><a href="<%= Linker.link("contests/submission.jsp?contest_id=" + contest.getId() + "&submission_id=" + submission.getId()) %>"><%= Formatters.formatJudgement(submission.getJudgement()) %></a></td>
<%
	if (contest.getShowScore() || contestUser.isJudge())
	{
%>			
			<td class="b1"><a href="<%= Linker.link("contests/submission.jsp?contest_id=" + contest.getId() + "&submission_id=" + submission.getId()) %>"><%= submission.getScore() >= 0 ? submission.getScore() : "-" %></a></td>
<%
	}
%>
<%
	if (contest.getShowWrongTest() || contestUser.isJudge())
	{
%>			
			<td class="b1"><%= submission.getWrongTestNumber() >= 0 ? submission.getWrongTestNumber() + 1 : "-" %></td>
<%
	}
%>
<%
	if (contest.getShowMaxTime() || contestUser.isJudge())
	{
%>			
			<td class="b1"><%= submission.getMaxTimeUsed() >= 0 ? submission.getMaxTimeUsed() + " мс" : "-" %></td>
<%
	}
%>
<%
	if (contest.getShowMaxMemory() || contestUser.isJudge())
	{
%>			
			<td class="b1"><%= submission.getMaxMemoryUsed() >= 0 ? (submission.getMaxMemoryUsed() / 1024) + " КБ" : "-" %></td>
<%
	}
%>
			<td class="b1"><%= submission.getDjudgeFlag() == -1 ? "На перевірці" : submission.getDjudgeFlag() == 0 ? "В черзі" : "ОК" %></td>
		</tr>
		<%
	}
%>
</table>


<%
	Long pageGenerationFinished = new Date().getTime();
%>
<!-- <%= "" + ((pageGenerationFinished - pageGenerationStarted)) + " ms" %>  -->

<%@ include file="footer.jsp" %>
